<script setup lang="js">
import { ref, watch, onMounted, onUnmounted } from 'vue'

const count = ref(0)
const link = ref('https://github.com/guocaoyi/create-chrome-ext')

const minus = () => {
  if (count.value > 0) count.value--
}
const add = () => count.value++

const openSidePanel = () => {
  chrome.runtime.sendMessage({ type: 'OPEN_SIDEPANEL' });
}

const openOptions = () => {
  chrome.runtime.openOptionsPage();
}

onMounted(() => {
  chrome.storage.sync.get(['count'], (result) => {
    count.value = result.count || 0
  })
})

watch(count, (newCount) => {
  chrome.storage.sync.set({ count: newCount })

  chrome.runtime.sendMessage({ type: 'COUNT', count: count.value })
})
</script>

<template>
  <main class="popup-main">
    <div class="popup-card">
      <h3>网页转内联样式</h3>
      <div class="calc">
        <button class="calc-btn" @click="minus" :disabled="count <= 0">-</button>
        <label class="calc-label">{{ count }}</label>
        <button class="calc-btn" @click="add">+</button>
      </div>
      <button class="sidepanel-btn" @click="openSidePanel">打开侧边栏</button>
      <button class="sidepanel-btn" @click="openOptions">打开扩展设置</button>
      <div class="footer">
        <a :href="link" target="_blank">由 create-chrome-ext 生成</a>
      </div>
    </div>
  </main>
</template>

<style>
:root {
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    Roboto,
    Oxygen,
    Ubuntu,
    Cantarell,
    'Open Sans',
    'Helvetica Neue',
    sans-serif;
  color-scheme: light dark;
  background: linear-gradient(135deg, #e8f5e9 0%, #f5f5f5 100%);
}

body {
  min-width: 22rem;
  color-scheme: light dark;
  background: none;
}

.popup-main {
  min-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
}

.popup-card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(66,185,131,0.13), 0 1.5px 6px rgba(44,143,124,0.08);
  padding: 1.2rem 1rem 1rem 1rem;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

h3 {
  color: #2c8f7c;
  text-transform: none;
  font-size: 1.6rem;
  font-weight: 600;
  margin: 0 0 2rem 0;
  letter-spacing: 1px;
}

.calc {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1.5rem 0 2rem 0;
  background: #f6faf8;
  border-radius: 2rem;
  box-shadow: 0 1px 4px rgba(66,185,131,0.07);
  padding: 0.7rem 1.5rem;
}

.calc-btn {
  font-size: 1.5rem;
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #42b983 60%, #2c8f7c 100%);
  color: #fff;
  cursor: pointer;
  margin: 0 1.2rem;
  box-shadow: 0 2px 8px rgba(66,185,131,0.13);
  transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}
.calc-btn:disabled {
  background: #e0e0e0;
  color: #bdbdbd;
  cursor: not-allowed;
  box-shadow: none;
}
.calc-btn:not(:disabled):hover {
  background: linear-gradient(135deg, #2c8f7c 60%, #42b983 100%);
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(66,185,131,0.18);
}

.calc-label {
  font-size: 2.2rem;
  font-weight: bold;
  color: #2c8f7c;
  margin: 0 1.2rem;
  min-width: 2.5rem;
  text-align: center;
}

.sidepanel-btn {
  margin-top: 0.7rem;
  padding: 0.7rem 2.2rem;
  background: linear-gradient(90deg, #42b983 0%, #2c8f7c 100%);
  color: #fff;
  border: none;
  border-radius: 0.7rem;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(66,185,131,0.15);
  transition: background 0.2s, transform 0.2s;
  margin-bottom: 0.3rem;
  width: 100%;
}
.sidepanel-btn:hover {
  background: linear-gradient(90deg, #2c8f7c 0%, #42b983 100%);
  transform: translateY(-2px) scale(1.03);
}

.footer {
  margin-top: 1.7rem;
  font-size: 1rem;
  color: #bdbdbd;
  text-align: center;
}
.footer a {
  color: #42b983;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s;
}
.footer a:hover {
  color: #2c8f7c;
}

@media (max-width: 400px) {
  .popup-card {
    min-width: 90vw;
    padding: 1.2rem 0.5rem 1rem 0.5rem;
  }
}

/* 隐藏滚动条 */
::-webkit-scrollbar {
  display: none;
}
body, .popup-main, .popup-card {
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
  overflow: hidden;
}

/* 自定义滚动条样式 */
::-webkit-scrollbar {
  width: 8px;
  background: #f0f7f4;
  border-radius: 8px;
}
::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #42b983 60%, #2c8f7c 100%);
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #2c8f7c 60%, #42b983 100%);
}
</style>
